package yxy.game.pm2.active.command.tengacha;

import yxy.apple.logger.Logger;
import yxy.cherry.data.bean.actbeforehand;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_十连预抽;
import yxy.game.pm2.active.module.actdata.ActDataCenter;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActTenGachaDisplayRequest;

@MessageType(proto = Command.ActTenGachaDisplay, classtype = ActiveMessage.ActTenGachaDisplayRequest.class)
public class CMD_Active_十连预抽_Display extends Command<ActTenGachaDisplayRequest> {

	private static final Logger logger = Logger.create(CMD_Active_十连预抽_Display.class);
	
	@Override
	public void execute(MessageSource messageSource, ActTenGachaDisplayRequest request) throws Exception {
		String pcode = messageSource.getTag();
		int type = request.getType();
		
		ActiveMessage.ActTenGachaDisplayResponse.Builder response = ActiveMessage.ActTenGachaDisplayResponse.newBuilder();
		
		ActiveModule_十连预抽 am = ActiveModule_十连预抽.get(pcode,false);
		if(am == null) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		if(!am.running()) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		if(am.getHerogroup().contains(type)) {
			send(messageSource, response, Result.ActHadGet);
			return;
		}
		
		actbeforehand execl = ActDataCenter.getData(am.getId(), actbeforehand.class, pcode);
		if(execl == null) {
			send(messageSource, response, Result.DataError);
			return;
		}
				
		if(am.getHerogroup().contains(type)) {
			send(messageSource, response, Result.ActHadGet);
			return;
		}
		
		am.getHerogroup().add(type);
//		am.getIdcodemap().put(id, taskbean.getCode());
		am.set();
		send(messageSource, response, Result.Success);
	}

	
	private void send(MessageSource messageSource, ActiveMessage.ActTenGachaDisplayResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}
